//package com.yzion.http.lifecycle
//
//import android.app.Dialog
//import androidx.appcompat.app.AppCompatActivity
//import androidx.fragment.app.Fragment
//import retrofit2.Call
//
//val callLifecycleObserverMap = HashMap<Call<*>, CallLifecycleObserver>()
//
//private fun check() {
//    callLifecycleObserverMap.values.forEach {
//        if (it.call.isCanceled && it.call.isExecuted) {
//            it.removeObserver()
//        }
//    }
//}
//
//fun Call<*>.cancelOnDismiss(dialog: Dialog): Call<*> {
//    check()
//    dialog.setOnDismissListener {
//        if (isCanceled.not() && isExecuted.not()) {
//            cancel()
//        } else {
//            unbindToLifeCycle()
//        }
//    }
//    return this
//}
//
//fun Call<*>.cancelOnDestroy(appCompatActivity: AppCompatActivity): Call<*> {
//    check()
//    callLifecycleObserverMap[this] = CallLifecycleObserver(appCompatActivity.lifecycle, this)
//    return this
//}
//
//fun Call<*>.cancelOnDestroy(fragment: Fragment): Call<*> {
//    check()
//    callLifecycleObserverMap[this] = CallLifecycleObserver(fragment.lifecycle, this)
//    return this
//}
//
///**
// * 当Call执行完后可以调用解除绑定
// */
//fun Call<*>.unbindToLifeCycle(): Call<*> {
//    callLifecycleObserverMap[this]?.let {
//        it.removeObserver()
//    }
//    return this
//}